<template>
  <Temp @clear="clear" @close="close">
    <div class="skyline">
      <div @click="pick">提取天际线</div>
      <div @click="start">开始分析</div>
    </div>
    <div id="skyLineChart"></div>
  </Temp>
</template>

<script>
import Temp from '../temp'
import { getAction } from '@/utils/helper'

const skyline = {}
export default {
  components: {
    Temp
  },
  inject: ['viewerId'],
  data() {
    return {
      controlBtnText: '开始分析'
    }
  },
  async created() {
    const { toolManager } = await getAction(this.viewerId)
    skyline[this.viewerId] = toolManager.skyline
  },
  methods: {
    close() {
      this.$emit('close')
    },
    clear() {
      const chartElement =
        document.getElementById('skyLineChart')
      if (chartElement) {
        chartElement.style.display = 'none'
      }
      skyline[this.viewerId] &&
        skyline[this.viewerId].clear()
    },
    pick() {
      this.clear()
      skyline[this.viewerId].pick()
    },
    start() {
      try {
        skyline[this.viewerId].start()
      } catch (e) {
        this.$message.error(e.message)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.skyline {
  display: flex;
  align-items: center;
  justify-content: space-around;

  & > div {
    border-radius: 2px;
    font-size: 14px;
    cursor: pointer;
  }

  div + div {
    margin-left: 10px;
  }
}

#skyLineChart {
  display: none;
  position: absolute;
  top: 50px;
  left: 0;
  width: 450px;
  height: 400px;
}
</style>
